package org.zyl.util.map;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.zyl.support.response.ResponseCode;

/**
 * 简化Map操作
 * 调用时Map<String, Object> page = MapUtil.getMapController().put("pageNo", 1).put("pageSize", 100).getMap();
 * @author yzzhouyalei@foxmail.com
 * @date 2016-12-28 15:58:25
 */
public class MapControlStr implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private Map<String, String> paramMap = new HashMap<String, String>();
	private MapControlStr(){}
	
	public MapControlStr init_param(String opcode,int version){
		paramMap.clear();
		paramMap.put("opcode", opcode);
		paramMap.put("version", version+"");
		return this;
	}
	
	public MapControlStr init_code(ResponseCode rc){
		paramMap.put("code", rc.getCode()+"");
		paramMap.put("text", rc.getText());
		return this;
	}
	
	public MapControlStr init_pagger(int count,int pageNo,int pageSize){
		paramMap.put("total", count+"");
		paramMap.put("pageCount", ""+(count%pageSize>0?(count/pageSize)+1:count/pageSize));
		paramMap.put("pageNo", pageNo+"");
		paramMap.put("pageSize", pageSize+"");
		return this;
	}
	
	public static MapControlStr getControl() {
		return new MapControlStr();
	}

	public MapControlStr put(String key, String value) {
		paramMap.put(key, value);
		return this;
	}
	public Map<String,String> getMap(){
		return paramMap;
	}
}